/**
 * Created by macos on 14/11/12.
 */

(function(){

  var root = this;
  var DeviceController = {}

  function createDevice(next) {

    Device.create(request)
      .exec(function(err, result){
        if(err) {
          return next(err);
        } else {
          return next(null, result);
        }
      });
  }

  /**
   * 注册设备信息
   * @param req
   * @param res
   */
  DeviceController.signin = function(req, res) {
    root.request = req.body;

    async.waterfall([
      createDevice
    ], function(err, result){
      if (err) {
        res.jsonResponse(400, err);
      } else {
        if (_.has(result, 'id')) {
          res.jsonResponse(200, result);
        }
      }
    })

  }

  module.exports = DeviceController
})()

